﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess.Classes
{
    public class ChiTietHangHoa
    {
        #region Anh xa cac cot trong bang => thuoc tinh
        private string _MaHangHoa;
        public string MaHangHoa
        {
            get { return _MaHangHoa; }
            set { _MaHangHoa = value; }
        }
        private string _CPU;
        public string CPU
        {
            get { return _CPU; }
            set { _CPU = value; }
        }
        private string _Ram;
        public string Ram
        {
            get { return _Ram; }
            set { _Ram = value; }
        }
        private string _HDD;
        public string HDD
        {
            get { return _HDD; }
            set { _HDD = value; }
        }
        private string _VGA;
        public string VGA
        {
            get { return _VGA; }
            set { _VGA = value; }
        }
        private string _Display;
        public string Display
        {
            get { return _Display; }
            set { _Display = value; }
        }
        private string _Webcam;
        public string Webcam
        {
            get { return _Webcam; }
            set { _Webcam = value; }
        }
        private string _Lan;
        public string Lan
        {
            get { return _Lan; }
            set { _Lan = value; }
        }
        private string _Wifi;
        public string Wifi
        {
            get { return _Wifi; }
            set { _Wifi = value; }
        }
        private string _Pin;
        public string Pin
        {
            get { return _Pin; }
            set { _Pin = value; }
        }
        private string _TrongLuong;
        public string TrongLuong
        {
            get { return _TrongLuong; }
            set { _TrongLuong = value; }
        }
        #endregion

        #region Ham
        public static List<ChiTietHangHoa> All()
        {
            return CBO.FillCollection<ChiTietHangHoa>(DataProvider.Instance.ExecuteReader("ChiTietHangHoa_All"));
        }

        public static ChiTietHangHoa Single(string maHangHoa) 
        {
            try 
            {
                ChiTietHangHoa dt = CBO.FillObject<ChiTietHangHoa>(DataProvider.Instance.ExecuteReader("ChiTietHangHoa_ChonMa", maHangHoa));
                return dt;
            }
            catch (Exception) { return null; }
        }
        public static bool Add(ChiTietHangHoa hanghoa)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ChiTietHangHoa_Them",
                hanghoa.MaHangHoa, hanghoa.CPU, hanghoa.Ram, hanghoa.HDD,
                hanghoa.VGA, hanghoa.Display, hanghoa.Webcam, hanghoa.Lan, hanghoa.Wifi, hanghoa.Pin, hanghoa.TrongLuong);
                return rs > 0;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update(ChiTietHangHoa hanghoa)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ChiTietHangHoa_Sua",
                hanghoa.MaHangHoa, hanghoa.CPU, hanghoa.Ram, hanghoa.HDD,
                hanghoa.VGA, hanghoa.Display, hanghoa.Webcam, hanghoa.Lan,
                hanghoa.Wifi, hanghoa.Pin, hanghoa.TrongLuong);
                return rs > 0;
            }
            catch
            {
                return false;
            }
        }
        public static bool Delete(string MaHangHoa)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ChiTietHangHoa_Xoa",
                MaHangHoa);
                return rs > 0;
            }
            catch
            {
                return false;
            }
        }
        #endregion
    }
}
